//This is pretty simple. It takes 100 readings and calculate the average.

//gyros
float inputGyroX[100];//x-axis
float resultGyroX;

float inputGyroY[100];//y-axis
long resultGyroY;

int inputGyroZ[100];//z-axis
long resultGyroZ;

//accelerometers
float inputAccX[100];//x-axis
float resultAccX;

float inputAccY[100];//y-axis
long resultAccY;

float inputAccZ[100];//z-axis
long resultAccZ;

//gyros
float calibrateGyroX()
{
  for(int i = 0; i < 100; i++)
  {
    delay(5);

    inputGyroX[i] = gyro.getX();

    Serial.print(inputGyroX[i], 0);Serial.print("\t");
  }
  
  for(int i = 0; i < 100; i++)
  {
    resultGyroX += inputGyroX[i];
  }

  Serial.print(resultGyroX, 0);Serial.print("\t");

  resultGyroX = resultGyroX / 100;

  Serial.print(resultGyroX, 0);Serial.print("\t");

   Serial.print("\n");

  return resultGyroX;
}

float calibrateGyroY()
{
  for(int i = 0; i < 100; i++)
  {
    inputGyroY[i] = gyro.getY();
  }
  
  for(int i = 0; i < 100; i++)
  {
    resultGyroY += inputGyroY[i];
  }

  resultGyroY = resultGyroY / 100;

  return resultGyroY;
}

float calibrateGyroZ()
{
  for(int i = 0; i < 100; i++)
  {
    inputGyroZ[i] = gyro.getZ();
  }

  for(int i = 0; i < 100; i++)
  {
    resultGyroZ += inputGyroZ[i];
  }

  resultGyroZ = resultGyroZ / 100;

  return resultGyroZ;
}

//accelerometers
float calibrateAccX()
{
  for(int i = 0; i < 100; i++)
  {
	//delay(10);

    acc.read();
    
    inputAccX[i] = acc.getGX();

  }

  for(int i = 0; i < 100; i++)
  {
    resultAccX += inputAccX[i];
  }

  resultAccX = resultAccX / 100;

  return resultAccX;
}
 
float calibrateAccY()
{
  for(int i = 0; i < 100; i++)
  {
    acc.read();
    
    inputAccY[i] = acc.getGY();
  }
  
  for(int i = 0; i < 100; i++)
  {
    resultAccY += inputAccY[i];
  }

  resultAccY = resultAccY / 100;

  return resultAccY;
}

float calibrateAccZ()
{
  for(int i = 0; i < 100; i++)
  {
    acc.read();

    inputAccZ[i] = acc.getGZ();
  }
  for(int i = 0; i < 100; i++)
  {
    resultAccZ += inputAccZ[i];
  }

  resultAccZ = resultAccZ / 100;

  return resultAccZ;
}
